<%--
  Created by IntelliJ IDEA.
  User: nguyentrongduy
  Date: 23/7/12
  Time: 5:11 PM
  To change this template use File | Settings | File Templates.
--%>

<%@ page contentType="text/html;charset=UTF-8" %>
<html>
<head>
  <meta name="layout" content="main">
  <title></title>
</head>
<body>
<div id="create-sanPham" class="content scaffold-create" role="main">
    <g:render template="/includes/includeUploadify" />

    <g:render template="/sanPham/createEditProduct/sanPhamHeader" model="['step':1]"></g:render>

    <g:if test="${flash.message}">
        <div class="message" role="status">${flash.message}</div>
    </g:if>

    <g:hasErrors bean="${sanPham}">

        <ul class="errors" role="alert">
            <g:eachError bean="${sanPham}" var="error">
                <li <g:if test="${error in org.springframework.validation.FieldError}">data-field-id="${error.field}"</g:if>><g:message error="${error}"/></li>
            </g:eachError>
        </ul>
    </g:hasErrors>

    <div class="marginLeftMiddle marginTopMiddle">
        <g:form>

            <table>
                <tr>
                    <td>
                        <g:message code="basicInfo.loai"></g:message> <span class="mustHaveElement">*</span>
                    </td>
                    <td>
                        <g:select class="many-to-one"
                                  name="loaiSanPham.id"
                                  from="${duylinh.LoaiSanPham.list()}"
                                  optionKey="id"
                                  optionValue="ten"
                                  value="${sanPham?.loaiSanPham}"
                        />
                    </td>
                </tr>

                <tr>
                    <td>
                        <g:message code="basicInfo.code"></g:message> <span class="mustHaveElement">*</span>
                    </td>
                    <td>
                        <input class="" type="text" name="code" size="30" value="${sanPham?.code}" />
                    </td>
                </tr>

                <tr>
                    <td>
                        <g:message code="basicInfo.photo"></g:message> <span class="mustHaveElement">*</span>
                    </td>

                    <td>
                        <img src="${sanPham.avatarUrl}" alt="" id="sanPhamAvatarImage"  width="100" height="100" />

                        <input id="sanPhamAvatarUrl" name="avatarUrl" type="hidden" value="${sanPham.avatarUrl}" />
                        <input id="avatarChanged" name="avatarChanged"  type="hidden" value="false" />

                        <dl:uploadify  class=""
                                       name="uploadAvatar"
                                       action= "${request.contextPath}/utils/uploadSanPhamAvatar"
                                       label="${message(code:'button.uploadBGImage')} : "
                                       multi = 'false'
                                       fileExt="*.jpg; *.png; *.gif"
                                       sizeLimit="${2048*2048}"
                                       onComplete="avatarOnComplete(response)"
                                       onProgress="myOnProgress(event, qId, fileObj, qData)"
                                       delay="500"
                        >
                        </dl:uploadify>


                        <g:javascript>
                            function avatarOnComplete(data){
                                $('#sanPhamAvatarImage').attr('src', data);
                                $('#sanPhamAvatarUrl').val(data);
                                $("#avatarChanged").val(true);
                            };

                        </g:javascript>


                    </td>
                </tr>


                <tr>
                    <td>
                        <g:message code="basicInfo.hangMuc"></g:message> <span class="mustHaveElement">*</span>
                    </td>
                    <td>
                        <g:select name="hangMuc"
                                  from="${['C', 'BL', 'N', 'CTKH', 'CTBL', 'CTK']}"
                                  value="${sanPham?.hangMuc}"
                                  valueMessagePrefix="hangmuc" />
                    </td>
                </tr>

                <tr>
                    <td>
                        <g:message code="basicInfo.donvi"></g:message> <span class="mustHaveElement">*</span>
                    </td>
                    <td>
                        <g:select class="many-to-one"
                                  name="donviSanPham.id"
                                  from="${duylinh.DonviSanPham.list()}"
                                  optionKey="id"
                                  optionValue="ten"
                                  value="${sanPham?.donviSanPham}"
                                  />
                    </td>
                </tr>

                <tr>
                    <td>
                        <g:message code="basicInfo.trongLuong"></g:message>
                    </td>
                    <td>
                        <span class="marginRightStd">
                            <input type="text" name="trongLuong" size="6" value="${sanPham?.trongLuong}" />
                        </span>

                        <g:select name="trongLuongDonvi"
                                  from="${['Kg', 'g']}"
                                  value="${sanPham?.trongLuongDonvi}"
                        />
                    </td>
                </tr>

                <tr>
                    <td>
                        <g:message code="basicInfo.priceBeforeTax"></g:message>
                    </td>
                    <td>
                        <span class="marginRightStd">
                            <input class="" type="text" name="priceBeforeTax" size="6" value="${sanPham?.priceBeforeTax}" />
                        </span>

                        <g:select name="currency"
                                  from="${['VND', 'USD']}"
                                  value="${sanPham?.currency}"

                        />
                    </td>
                </tr>


                <tr>
                    <td>
                        <g:message code="basicInfo.ghiChu"></g:message>
                    </td>
                    <td>
                        <g:textArea name="ghiChu" rows="20" cols="8">${sanPham?.ghiChu}</g:textArea>
                    </td>
                </tr>

            </table>


            <fieldset class="buttons marginTopMiddle">
                <div class="floatL">
                    <g:submitButton name="huy" class="cancel" value="${message(code:'button.huy')}" />
                    <g:submitButton name="tiep" class="save" value="${message(code:'button.tieptuc')}" />
                </div>


                <div class="floatR marginRightStd">
                    <g:submitButton name="ketthuc" class="save" value="${message(code:'button.ketthuc')}" />
                </div>

                <div class="clear"></div>

            </fieldset>

        </g:form>
    </div>


</div>
</body>
</html>